import { Component, OnInit, Injector } from '@angular/core';
import { CityListComponent } from '../../school/cityList';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { HttpClient } from "@angular/common/http";
import { Router, ActivatedRoute, Params } from '@angular/router';
import { NgZorroPageBaseComponent } from '../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import {
  PagedResultDto, ClassInfoOutput, PagerSearchInput, HttpService, BaseComponentConfig,
  CustomNavigation, KeyValueOutput, SearchValue
} from '../../..';
@Component({
  selector: 'app-classedit',
  templateUrl: './classedit.component.html',
  styleUrls: ['./classedit.component.scss']
})
export class ClasseditComponent extends NgZorroPageBaseComponent implements OnInit {
  classid;
  className; // 班级
  remark; // 备注
  project = []; // 项目
  departmentName; // 系
  allstudentdata;
  checkOptionsOne = [
    { label: 'Apple', value: 'Apple', checked: false },
  ];
  radioValue = 'true';
  selectedProvince;
  selectedCity;
  cityData: any;
  time = "2018-07-30";
  schoolName;
  personName = "";
  personPhone = "";
  personEmail = "";
  personUserName = "";
  personPassword = "";
  collegelName;
  provinceData: any;
  mess: any;
  resute = [];
  resute1 = [];
  resultxy = [];
  listEntitiesscl;
  timelist = new Array();
  ilist = 0;
  listEntitiesdata: any;
  aclear;
  listprodata;
  ngOnInit() {
    // 获取班级传过来的ID
    this.activatedRoute.queryParams.subscribe(
      data => this.classid = (data['classId']));
    if (this.classid !== "add") {

    }

    this.IniObserver.subscribe(sb => {
      this.getEntityList();
    });



  }
  constructor(injecter: Injector,
    public http1: HttpService,
    public http: HttpClient,
    private activatedRoute: ActivatedRoute,
  ) {
    super(injecter,
      new BaseComponentConfig(
        "School/GetAllDepartment",
        "",
        "",
        "",
        "",
        "id",
        "",
        "学校管理",
        [],
        "",
        { Edit: false, Dell: false },
      ));
    const city = new CityListComponent;
    this.cityData = city.cityDatas;
    this.provinceData = city.provinceDatas;


    const datalist1 = {
      "currentPageIndex": 1,
      "pageSize": 10,
      "expressionPairs": [
      ],
      "sortExpressions": [
      ]
    };
    this.http1.post<any>('DrillProject/GetAll', datalist1).then(e => {
      this.listprodata = e.entities;
    });




  }


  provinceChange(value: string): void {
    this.selectedCity = this.cityData[value][0];
  }
  /**
   * 保存學校信息
   *
   */


  async serve(type: string) {

    const that = this;
    const data = {
      "className": this.className, "collegeDepartmentId": this.departmentName, "description": this.remark, "drillProjectIdList": this.project
    };
    if (this.className === "" || this.departmentName === "undefined" || this.remark === "" || this.project[0] === "undefined" || !this.departmentName || !this.project[0]) {
      that.message.info('请填写完整');
      return false;
    } else {


      await that.http1.post<any>("ClassInfo/Create", data);

      this.message.create(type, `保存成功`);

      this.router.navigate(['app/classindex']);

    }

  }

  delete() {

  }
  async provinceChangesol(e) {
    this.departmentName = e;
  }
  async projectdata(e) {
    this.project = [];
    this.project.push(e);
  }

  async searchChange(searchText: string) {
    const that = this;
    clearTimeout(this.aclear);
    this.aclear = setTimeout(() => {
      that.sealist(searchText);
    }, 1000);


  }


  sealist(i) {
    const datalist = { "Name": i };
    this.listEntitiesdata = [];
    this.http1.post<any>("School/GetSchoolToTen", datalist).then(e => {
      this.listEntitiesdata = e;

    });
  }


}

